package com.mallcai.bigdata.ladon.vo.system;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 树型节点
 * Created by oneape<oneape15@163.com>
 * Created 2019-06-29 15:15.
 * Modify:
 */
@Data
public class TreeNodeVo implements Serializable {
    private String key;   // 此项必须设置（其值在整个树范围内唯一）
    private String value; // 默认根据此属性值进行筛选（其值在整个树范围内唯一）
    private String title; // 树节点显示的内容
    private String icon;

    private Map<String, String> props = new HashMap<>(); // 节点额外属性值

    private List<TreeNodeVo> children;
    private boolean isLeaf   = false; // 是否是叶子节点
    private boolean disabled = false; // 是否禁用

    public TreeNodeVo(String key, String title) {
        this.key = key;
        this.title = title;
        this.value = key;
    }

    public TreeNodeVo(String key, String title, String icon) {
        this.key = key;
        this.value = key;
        this.title = title;
        this.icon = icon;
    }

    public void addChildren(List<TreeNodeVo> tmp) {
        if (tmp == null) {
            return;
        }

        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        children.addAll(tmp);
    }
}
